<%= render partial: 'shipit/stacks/header', locals: { stack: @stack } %>

<% if !@stack.ignore_ci && !@stack.ci_enabled? %>
  <div class="banner">
    <div class="banner__inner wrapper">
      <div class="banner__content">
        <h2 class="banner__title">Heads Up!</h2>
        <p class="banner__text">
          This stack is not configured for CI, but it currently requires a passing build to be able to deploy a commit.<br>
          You can either <a href="https://developer.github.com/v3/repos/statuses/">configure your CI to push statuses to GitHub</a>,
          or ignore CI and deploy any commits you want.
        </p>
        <%= button_to "Ignore CI", stack_path(@stack, stack: {ignore_ci: true}, return_to: stack_path(@stack)), method: :patch, class: 'banner__btn btn' %>
      </div>
    </div>
  </div>
<% end %>

<% if @stack.inaccessible? %>
  <div class="banner banner--red">
    <div class="banner__inner wrapper">
      <div class="banner__content">
        <h2 class="banner__title">This repository seems to be missing!</h2>
        <p class="banner__text">
          <%= link_to @stack.github_repo_name, github_repo_url(@stack.repo_owner, @stack.repo_name) %>
          has been inaccessible for <%= time_ago_in_words(@stack.inaccessible_since) %>.

          This could be a permission issue, or the repository have been deleted on GitHub.
        </p>
      </div>
    </div>
  </div>
<% end %>

<% if @stack.locked? %>
  <div class="banner banner--orange">
    <div class="banner__inner wrapper">
      <div class="banner__content">
        <h2 class="banner__title">
          <i class="icon icon--lock"></i>
          Deploys are locked by <%= @stack.lock_author.name %>
        </h2>
        <p class="banner__text">
          <%= auto_link emojify(@stack.lock_reason) %>
        </p>
      </div>
    </div>
  </div>
<% end %>

<% if @stack.continuous_delivery_delayed? %>
  <div class="banner">
    <div class="banner__inner wrapper">
      <div class="banner__content">
        <h2 class="banner__title">Continuous Delivery Delayed!</h2>
        <p class="banner__text">
          Continuous Delivery for this stack is currently paused because
          <%= link_to 'the pre-deploy checks failed', stack_commit_checks_path(@stack, sha: @stack.next_commit_to_deploy.sha) %>.
          You can either wait for them to pass, or trigger a deploy manually.
        </p>
      </div>
    </div>
  </div>
<% end %>

<div class="wrapper" data-event-stream="<%= events_path(channels: ["stack.#{@stack.id}"]) %>">

  <section>
    <header class="section-header">
      <h2>Undeployed Commits</h2>

      <div class="commit-list-actions">
        <% if params[:force] %>
          <%= link_to 'Exit emergency mode', stack_path(@stack) %>
        <% else %>
          <%= link_to 'Enable emergency mode', stack_path(@stack, force: 1) %>
        <% end %>
      </div>
    </header>
    <ul class="commit-list">
      <%= render partial: 'shipit/commits/commit', collection: @commits %>
    </ul>
  </section>

  <section>
    <header class="section-header">
      <h2>Previous Deploys</h2>
    </header>
    <ul class="commit-list"><%= render @tasks %></ul>
  </section>
</div>
